$(function () {
    layui.use('carousel', function () {
        var carousel = layui.carousel;
        // 引入图片
        function loadSwiperList() {
            $.ajax({
                url: 'http://124.223.31.209:5858/api/swipers',
                type: 'GET',
                success: function (res) {
                    console.log(1);
                    if (res.status === 0) {
                        var arr = []
                        res.data.forEach((item) => {
                            arr.push(`
                                <li class="img-effect">
                                    <a href="javascript:;">
                                        <img src="${'http://124.223.31.209:5858/uploads/' + item.swiperimg}">
                                    </a>
                                </li>
                            `)
                        });
                        $('#kr_carousel ul').html(arr.join(''))
                        //建造实例
                        carousel.render({
                            elem: '#kr_carousel'
                            , width: '720' //设置容器宽度
                            , arrow: 'hover' //始终显示箭头
                            , height: '300'
                            , interval: '2500'
                        });
                    }
                }
            })
        }
        loadSwiperList()

        // 友情连接模块
        function loadLinkList() {
            $.ajax({
                url: 'http://124.223.31.209:5858/api/links',
                type: 'GET',
                success: function (res) {
                    if (res.status === 0) {
                        var arr = ['<dt>合作伙伴</dt>']
                        res.data.forEach(function (item) {
                            arr.push(`
                        <dd>
                            <a href="${item.linkurl}">
                                <img src="${'http://124.223.31.209:5858/uploads/' + item.linkicon}">
                            </a>
                        </dd>
                        `)
                        })
                        $('.kr_collaborator').html(arr.join(''))
                    }
                }
            })
        }
        loadLinkList()
    });
})
